class Solution {
public:
    int search(vector<int>& nums, int target) {
        int left = 0;int right = nums.size()-1;
        while(left<=right)
        {
            int mid = (left+right)/2;
            if(nums[mid] == target)
            {
                return mid;
            }
            if(nums[mid]>=nums[left])
            {
                //mid左边区域是有序的
                (nums[left]<=target&&target<nums[mid])?right = mid-1:left=mid+1;//左边有序并且target就在
                //左边区域所以让right变到左边区域，否则就去右边区域寻找
            }
            else
            {
                //右边区域是有序的
                (nums[mid]<target&&target<=nums[right])?left = mid+1:right = mid-1;
            }
        }
        return -1;
        
    }
};